﻿using EmitMapper;
// ***********************************************************************
// Assembly         : MVC4Portal
// Author           : LJO+01
// Created          : 09-29-2013
//
// Last Modified By : Lolo
// Last Modified On : 09-30-2013
// ***********************************************************************
// <copyright file="AdminUsersController.cs" company="">
//     Copyright (c) . All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using InnovaApp.Layers.DataLayer;
using InnovaApp.Layers.DomainLayer;
using InnovaApp.Layers.ResourcesLayer.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Http.OData;
using System.Web.Http.OData.Query;
using System.Web.Security;

/// <summary>
/// The ODataControllers namespace.
/// </summary>
namespace InnovaApp.Portals.MVC4Portal.Controllers.ODataControllers
{
    /// <summary>
    /// Class AdminUsersController.
    /// </summary>
    [Authorize(Roles = "Admin")]
    public class AdminUsersController : _ODataControllers_Base
    {
        /// <summary>
        /// Gets the specified options.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <returns>PageResult{v_AdminUsers}.</returns>
        public PageResult<v_AdminUsers> Get(ODataQueryOptions options)
        {
            PageResult<v_AdminUsers> toReturn;
            DataRepositories _dataContext = new DataRepositories();
            var dbList = _dataContext.v_AdminUsers_Rep.GetAll().ToList();
            //Mapping to fix the EDMX generation error that make all columns as key
            IEnumerable<v_AdminUsers> results = ObjectMapperManager.DefaultInstance.GetMapper<List<v_AdminUsers>, List<v_AdminUsers>>().Map(dbList);
            foreach (var c in results)
            {
                if (c.Genre != null)
                {
                    c.Genre = INNOVACALL.Framework.Common.MVCHelpers.Localization.CommonLocalization.LookupResource(typeof(Resources), c.Genre);
                }
            }
            results = (IEnumerable<v_AdminUsers>)options.ApplyTo(results.AsQueryable());
            toReturn = new PageResult<v_AdminUsers>(results, Request.GetNextPageLink(), Request.GetInlineCount());
            return toReturn;
        }
    }
}
